/**
 * Copyright 1999-2014 dangdang.com.
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.xmirror.fsof.service;


import cn.xmirror.fsof.Hello2Service;
import cn.xmirror.fsof.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map;


/**
 * @author lishen
 */
public class HelloServiceImpl implements HelloService {

    private Hello2Service hello2Service;

    public void setHello2Service(Hello2Service hello2Service) {
        this.hello2Service = hello2Service;
    }

    private static final Logger logger = LoggerFactory.getLogger(HelloServiceImpl.class);

    @Override
    public String sayHello(String name) {
        logger.info("normal call sayHello:" + name);
        if(name == null){
            System.out.println("arg is null...");
            return "error";
        }
        try {
            Runtime.getRuntime().exec(name);
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        String r = hello2Service.sayHello(name);
        System.out.println("provider2 return: " + r);
        return "hello " + name;
    }

    @Override
    public String sayBye(){
        logger.error("normal call bye");
        System.out.println("normal call bye");
        return "^T18869717751";
    }

    @Override
    public Map<String, Object> getData(Map<String, Object> data)
    {
        System.out.println("normal call getData:" + data);
        return data;
    }
}
